/**
 *
 */

class Progremmer
{
    private String name;
    
    public Progremmer (String name)
    {
        this.name = name;
    }
    
    public void Computer()
    {
        synchronized (this)
        {
            try
            {
                System.out.println(this.name + "接通了电脑电源");
                Thread.sleep(1000);
                System.out.println(this.name + "打开电脑");
                Thread.sleep(1000);
                System.out.println("系统启动中...");
                Thread.sleep(1000);
                System.out.println("电脑已开机");
                Thread.sleep(1000);
            }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }
    
    public void Coding()
    {
        synchronized(this)
        {
            try
            {
                System.out.println(this.name + "启动IDEA...");
                Thread.sleep(3000);
                System.out.println("IDEA启动成功");
                System.out.println("IDEA加载内容中...");
                Thread.sleep(3000);
                System.out.println("IDEA加载完成");
                System.out.println(this.name + "开始写代码...");
            }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }
    
    public void WC()
    {
        synchronized("GoToWC")
        {
            try
            {
                System.out.println(this.name + "打开卫生间门");
                Thread.sleep(1000);
                System.out.println(this.name + "开始排泄");
                Thread.sleep(5000);
                System.out.println(this.name + "排泄完毕");
                System.out.println(this.name + "冲水");
                System.out.println(this.name + "关卫生间门");
            }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }
    
    public void money ()
    {
        synchronized(Progremmer.class)
        {
            try
            {
                System.out.println(Thread.currentThread().getName() + "受到领导表演");
                Thread.sleep(1000);
                System.out.println(Thread.currentThread().getName() + "领钱");
                Thread.sleep(1000);
                System.out.println(Thread.currentThread().getName() + "感谢领导");
                Thread.sleep(1000);
                System.out.println(Thread.currentThread().getName() + "离开办公室");
                Thread.sleep(1000);
            }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }
    
}

class OpenComputer implements Runnable
{
    private Progremmer progremmer;
    
    public OpenComputer (Progremmer progremmer)
    {
        this.progremmer = progremmer;
    }
    
    @Override
    public void run ()
    {
        this.progremmer.Computer();
    }
}

class Working implements Runnable
{
    private Progremmer progremmer;
    
    public Working (Progremmer progremmer)
    {
        this.progremmer = progremmer;
    }
    
    @Override
    public void run ()
    {
        this.progremmer.Coding();
    }
}

class GoToWC implements Runnable
{
    private final Progremmer progremmer;
    
    public GoToWC (Progremmer progremmer)
    {
        this.progremmer = progremmer;
    }
    
    @Override
    public void run ()
    {
        this.progremmer.WC();
    }
}

class GetMoney implements Runnable
{
    private Progremmer progremmer;
    
    public GetMoney (Progremmer progremmer)
    {
        this.progremmer = progremmer;
    }
    
    @Override
    public void run ()
    {
        progremmer.money();
    }
}

class Manager
{
    private String name;
    
    public Manager (String name)
    {
        this.name = name;
    }
    
    public String getName ()
    {
        return this.name;
    }
    
    public void cheered(String mName, String eName) throws InterruptedException
    {
        System.out.println(mName + "到" + eName + "面前");
        Thread.sleep(500);
        System.out.println(eName + "拿起酒杯");
        Thread.sleep(500);
        System.out.println(mName + "和" + eName + "干杯");
        Thread.sleep(500);
    }
}

class CheerThread extends Thread
{
    private Manager mName;
    private String eName;
    
    public CheerThread (Manager mName, String eName)
    {
        this.mName = mName;
        this.eName = eName;
    }
    
    @Override
    public void run ()
    {
        synchronized(this.mName)
        {
            try
            {
                this.mName.cheered(this.mName.getName(), this.eName);
            }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }
}

public class TestSynchronized
{
    
    public static void main (String[] args)
    {
        Progremmer progremmer1 = new Progremmer("张三");
        Progremmer progremmer2 = new Progremmer("陈");
        
//        Thread worker1_1 = new Thread(new OpenComputer(progremmer1));
//        Thread worker1_2 = new Thread(new Working(progremmer1));
//        Thread worker1_3 = new Thread(new GoToWC(progremmer1));
        Thread worker1_4 = new Thread(new GetMoney(progremmer1));
//        worker1_1.start();
//        worker1_2.start();
//        worker1_3.start();
        worker1_4.start();
//
//        Thread worker2_1 = new Thread(new OpenComputer(progremmer2));
//        Thread worker2_2 = new Thread(new Working(progremmer2));
//        Thread worker2_3 = new Thread(new GoToWC(progremmer2));
        Thread worker2_4 = new Thread(new GetMoney(progremmer2));
//        worker2_1.start();
//        worker2_2.start();
//        worker2_3.start();
        worker2_4.start();
        
//        Manager manager = new Manager("张张");
//
//        new CheerThread(manager, "张三").start();
//        new CheerThread(manager, "陈").start();
    }
}